//
//  BSTagCell.m
//  BaiSi
//
//  Created by Sycamore on 16/4/28.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "BSTagCell.h"
#import "BSTagItem.h"
#import <UIImageView+WebCache.h>
#import "UIImage+Resize.h"
#import "BSUsersItem.h"
@interface BSTagCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *name;

@property (weak, nonatomic) IBOutlet UILabel *count;

@end
@implementation BSTagCell

+ (instancetype)tagCell
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]firstObject];
}

- (void)awakeFromNib {
    // Initialization code
    
    //这个属性在ios9以下会导致掉帧
//    _iconView.layer.cornerRadius = _iconView.bs_width * 0.5;
//    _iconView.layer.masksToBounds = YES;
    
    self.autoresizingMask = UIViewAutoresizingNone;
}


//新帖－－推荐
- (void)setItem:(BSTagItem *)item
{
    _item = item;
    
    [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        //除了diwnloader，sdWebImage所有的回调都是在主线程里面进行的
        if (image) {
            _iconView.image = [UIImage clipRoundImage:image];
        }
        else{
            _iconView.layer.cornerRadius = _iconView.bs_width * 0.5;
            _iconView.layer.masksToBounds = YES;
        }
    }];
    _name.text = item.theme_name;
    
    
    NSInteger subCount = [item.sub_number integerValue];
    CGFloat count = subCount / 10000.0;
    if (count  >= 1) {
        _count.text = [NSString stringWithFormat:@"%.1f万人订阅",count];
        if ([_count.text containsString:@"0"]) {
            //记住，转了之后一定要在次赋值，转了不赋值是没用的
           _count.text = [_count.text stringByReplacingOccurrencesOfString:@".0" withString:@""];
        }
    }else {
        _count.text = [NSString stringWithFormat:@"%ld人订阅",subCount];
    }

    
}

//关注－－推荐
- (void)setUsersItem:(BSUsersItem *)usersItem
{
    _usersItem = usersItem;
    
    [_iconView sd_setImageWithURL:[NSURL URLWithString:usersItem.header] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        //除了diwnloader，sdWebImage所有的回调都是在主线程里面进行的
        if (image) {
            _iconView.image = [UIImage clipRoundImage:image];
        }
        else{
            _iconView.layer.cornerRadius = _iconView.bs_width * 0.5;
            _iconView.layer.masksToBounds = YES;
        }
    }];
    _name.text = usersItem.screen_name;
    
    
    NSInteger subCount = [usersItem.fans_count integerValue];
    CGFloat count = subCount / 10000.0;
    if (count  >= 1) {
        _count.text = [NSString stringWithFormat:@"%.1f万人关注",count];
        if ([_count.text containsString:@"0"]) {
            //记住，转了之后一定要在次赋值，转了不赋值是没用的
            _count.text = [_count.text stringByReplacingOccurrencesOfString:@".0" withString:@""];
        }
    }else {
        _count.text = [NSString stringWithFormat:@"%ld人关注",subCount];
    }

}

- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 0.8;
    
    [super setFrame:frame];
}


@end
